// @ts-nocheck
import runSaga from './runSaga'
import Channel from './Channel'

/**
 * 创建saga中间件的函数
 * @export
 */
export default function createSagaMiddleware(options) {
    return function sagaMiddleware(store) {
        const chanel = new Channel()
        // 全局环境信息
        const env = { store, chanel }
        sagaMiddleware.run = runSaga.bind(null, env)
        return function createDispatch(next) {
            return function dispatch(action) {
                const result = next(action); // 先交给下一个中间件
                // 发布订阅 
                chanel.put(action.type, result);
                return result;
            }
        }
    }
}


